package com.teacherprofile.manage.config;

import com.teacherprofile.manage.service.ISoftwareCopyrightsService;
import com.teacherprofile.manage.service.impl.SoftwareCopyrightsServiceImpl;
import com.teacherprofile.manage.tools.ServiceTools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbacks;
import org.springframework.ai.zhipuai.ZhiPuAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author vibelin
 */
@Configuration
public class AIConfig {
    @Bean
    public ChatClient chatClient(ZhiPuAiChatModel model, ChatMemory chatMemory, ServiceTools service) {
        ToolCallback[] from = ToolCallbacks.from(service);
        return ChatClient.builder(model)
                .defaultTools(from)
                .defaultSystem("你是一个AI智能助手,名字叫做六六，如果用户让你执行查询的代码，那么你需要格式化输出，如果遇到敏感信息注意加密处理")
                .defaultAdvisors(new SimpleLoggerAdvisor(), new MessageChatMemoryAdvisor(chatMemory)) // 添加日志增强
                .build();
    }

    @Bean
    public ChatMemory chatMemory() {
        return new ChatRedisMemory();
    }


}
